﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using NHibernate;
using NHibernate.Linq;
using Entities;
using RepositoriesInterfaces;

namespace Repositories
{
    public class GroupRepository : BaseRepository<Group>, IGroupRepository
    {
        public GroupRepository(ISession session)
        {
            this._session = session;
        }

        public IList<Group> GetBySPItemsList(IList<StudyPlanItem> SPItemList)
        {
            List<Group> groupsList = new List<Group>();
            _session.BeginTransaction();
            foreach (StudyPlanItem SPItem in SPItemList)
            {
                groupsList.AddRange((from s in _session.Query<Group>()
                                     where s.Direction == SPItem.Direction
                                     where s.Course == Math.Ceiling((double)SPItem.Semestr / 2)
                                     select s).Distinct().ToList());
            }
            _session.Transaction.Commit();

            return groupsList;
        }
    }
}